#ifndef CODE_OBJECT_HPP
#define CODE_OBJECT_HPP

#include <vector>
using namespace std;

#include "codegen.hpp"

class CodeObject {
private:
    vector<Constant>        _consts;
    vector<string>          _names;
    vector<string>          _var_names;
    vector<string>          _frees;
    vector<string>          _cells;
    string                  _file_name;
    string                  _module_name;
    int                     _begin_lineno;
    string                  _lnotab;

    vector<unsigned char>   _insts;
    int                     _arg_count;
    int                     _nlocals;
    int                     _stack_size;
    int                     _flags;

public:
    CodeObject(int arg_count, int nlocals, int stack_size, int flags, 
        vector<unsigned char>& insts,
        vector<Constant>& consts,
        vector<string>& names,
        vector<string>& var_names,
        vector<string>& free_vars,
        vector<string>& cell_vars) :
        _arg_count(arg_count), _nlocals(nlocals), _stack_size(stack_size),  
        _flags(flags), _insts(insts), _consts(consts), _names(names),
        _var_names(var_names), _frees(free_vars), _cells(cell_vars)
    {}

    static int write_to_file(string& filename, CodeObject& co);
    int save_to_file(ofstream& file);
    int save_code_to_file(ofstream& file);

    template<typename T>
    int save_const_value(T t, ofstream& file);

    int save_vector(ofstream& file, vector<Constant>& v);
    int save_vector(ofstream& file, vector<string>& v);
    int save_string(ofstream& file, string& s);
};

#endif
